﻿using System;
using System.Data;
using System.IO;
using Microsoft.Data.Sqlite;
using ZilLion.Service.Core.ConfigManager.Manager;
using ZilLion.Service.Core.DapperWrapper;

namespace ZilLion.Service.Core.SqliteWrapper
{
    public class DefaultSqliteDbContext : IDbContext
    {
        private readonly string _sqliteConnectionString;

        public DefaultSqliteDbContext()
        {
            var config = ZilLionConfigurationManager.GetConfigInstance<SqliteConfig>();
            var builder = new SqliteConnectionStringBuilder
            {
                DataSource =
                    Path.Combine(config.DbFiledirectory ?? AppDomain.CurrentDomain.BaseDirectory, config.DbFileName)
            };
            _sqliteConnectionString = builder.ToString();

            //todo builder.Password
        }


        public string ContextName => "DefaultSqliteDbContext";

        public IDbConnection GetConnection()
        {
            return new SqliteConnection("Data Source=TaskManagerConfig.db");
        }
    }
}